<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //请写一个函数，打印一个字符串中的第一个不重复的字符
      /*       function fn(str) {
              const map = {}
              for (let i = 0; i < str.length; i++) {
                if (!map[str[i]] && str.indexof(str[i], i + 1) === -1) {
                  return str[i]
                }
                map[str[i]] = true
              }
            }
            console.log(fn('aaaabbbcddcerr')) // e */

      function fn(str) {
        const arr = str.split('')
        const arr2 = str.split('')
        const newarr = []
        for (let i = arr2.length - 1; i >= 0; i--) {
          arr.splice(i, 1)
          if (!arr.includes(arr2[i])) {
            newarr.push(arr2[i])
          }
          arr.push(arr2[i])
        }
        return newarr[newarr.length - 1]
      }
      console.log(
        fn(
          'dfsfvdvnuiooswidjdknfvkcnsmdhavbcjfkuldkdfjsdvamcgbfnpkdcgfbgfjdshjvnklgjxjvkccnkxjckvbvfdskkcvvncgfdjkldpkvndgfhfjslkdcvjbcfidcndwerfkjbj'
        )
      )

      /*       try {
        //aabbccdee
        //请写一个函数，打印一个字符串中的第一个不重复的字符
        const str = 'aabbccddeffg'
        function fn(str) {
          //字符串转数组
          const arr = str.split('') //一项一项筛选
          for (let i = 0; i < arr.length; i++) {
            let newArr = arr.filter((item) => {
              return item === arr[i]
            })
            if (newArr.length >= 2) continue
            if (newArr.length < 2) {
              console.log(newArr[0])
              return
            }
          }
        }
        fn(str)
      } catch (error) {
        console.log(error)
      } */

      // let str =
      //   'dfsfvdvnuiooswidjdknfvkcnsmdhavbcjfkuldkdfjsdvamcgbfnpkdcgfbgfjdshjvnklgjxjvkccnkxjckvbvfdskkcvvncgfdjkldpkvndgfhfjslkdcvjbcfidcndwerfkjbj'
      // for (let x of str) {
      //   let reg = new RegExp(`${x}`, 'g') //创建正则
      //   if (str.match(reg).length == 1) {
      //     //匹配正则，如果匹配超过1个，则表示有重复，跳过
      //     //如果只匹配到一个，则输出
      //     console.log(x) //输出第一个不重复的字符
      //     break
      //   }
      // }
    </script>
  </body>
</html>
